{extend name="base" /}
{block name="content"}
<div class="content">
    <div class="container-fluid">
        <!-- Page-Title -->
    <div class="row">
        <div class="col-12">
            <div class="page-title-box">
                <div class="page-title-right">
                    <ol class="breadcrumb m-0">
                        <li class="breadcrumb-item"><a href="{:url('index/index')}"><i class="fe-home"></i> 控制台</a></li>
                        <li class="breadcrumb-item"><a href="javascript: void(0);">系统管理</a></li>
                        <li class="breadcrumb-item active">系统日志</li>
                    </ol>
                </div>
                <h4 class="page-title"> <i class="fe-shopping-bag"></i> 系统日志</h4>
            </div>
        </div>
        <div class="col-lg-12">
            <div class="card-box">
                <div class="table-responsive">
                <h4 class="header-title mb-4">系统日志列表 <span style="font-size: 12px;color: #999; letter-spacing: 1px;">共{$list->total()}条日志记录</span></h4>
                <div class="col-10 text-sm-center form-inline">
                        <form class="navbar-form form-inline" action="/admin/system/syslog" method="get">
                        <div class="form-group mr-2">
                            <select id="demo-foo-filter-status" class="custom-select custom-select-sm" name="type">
                                <option value="">--日志类型--</option>
                                <option value="1" {if $Think.get.type == 1}selected{/if} >登录日志</option>
                                <option value="2" {if $Think.get.type == 2}selected{/if} >操作日志</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <input id="demo-foo-search" type="text" value="{$Think.get.keywords}" placeholder="操作用户" class="form-control form-control-sm" name="keywords">
                        </div>
                        <div class="form-group">
                            <button type="submit" class="form-control form-control-sm btn-sm btn-success" style="cursor: pointer;margin-right: 10px;margin-left: 10px;"><i class="fe-search"></i> 搜索</button>
                        </div>
                        </form>
                        <div class="form-group">
                            <button onclick="del(this)" type="button" class="btn btn-sm btn-danger waves-effect waves-light"><i class="fe-trash-2"></i> 清空日志</button>
                        </div>
                    </div>
                    <br/>
                    <table class="tablesaw table table-hover">
                        <thead>
                            <tr>
                                <th>日志类型</th>
                                <th>操作用户</th>
                                <th>IP</th>
                                <th>操作时间</th>
                                <th>内容</th>
                            </tr>
                        </thead>
                        <tbody class="tbody">
                            {empty name="$list"}
                            <tr>
                                <td colspan="5" id="colspanTbal">
                                    <span class="fe-alert-triangle"></span> 暂无数据～
                                </td>
                            </tr>
                            {/empty}
                            {foreach $list as $key => $val}
                            <tr>
                                <td>{$val.type==1 ? '登录日志' : '操作日志'}</td>
                                <td>{$val.username}</td>
                                <td>{$val.ip}</td>
                                <td>{:date('Y-m-d H:i:s', $val['create_at'])}</td>
                                <td class="text-danger">{$val.content}</td>
                            </tr>
                            {/foreach}
                        </tbody>
                    </table>
                </div>
                <!--分页位置-->
                {$list->render()}
            </div>
        </div> <!-- end col -->
    </div>
    </div> <!-- container -->

</div> <!-- content -->
<script src="/static/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['element', 'form', 'layedit','upload'], function () {
        var form = layui.form;
        var $ = layui.jquery,upload = layui.upload;
    })
    function del(e){
        layer.confirm('确认一键清空所有日志？', {
            btn: ['确定','取消'],
            title: '操作提示',
            icon: 7,
        }, function(){
            $.post('/admin/system/syslog_del',{},function(res){
                if(res.code == 0){
                    layer.msg(res.message,{icon:1, shade: [0.2, '#ccc'], time: 1000});
                    setTimeout(function(){
                        window.location.href=res.data.url;
                    },1000);
                }else{
                    layer.msg(res.message,{icon:5, anim: 6});
                }
            },'json');
        });
    }
</script>
{/block}